home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 2746 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.1 KB  |  41 lines

  1. Newsgroups: comp.lang.c
  2. Path: server.blaze.net.au!csource!not-for-mail
  3. From: Andrew.Nesbit@f396.n634.z3.fidonet.org (Andrew Nesbit)
  4. Subject: help with pi algorithm
  5. Sender: news@blaze.net.au (news)
  6. Organization: FidoNet: ZWSBBS +61-3-98276881 28800bps Multiline 
  7. Message-ID: <0fc_9601240111@csource.blaze.net.au>
  8. X-Nntp-Posting-Host: csource.blaze.net.au
  9. Date: Tue, 23 Jan 1996 04:44:36 GMT
  10.  
  11. Hi all!
  12.  
  13. I am a newbie C programmer trying to write an algorithm to work out the
  14. value of pi fairly accurately. I have written the following code, but I'm
  15. not sure whether it's considered 'nasty' programming, or whether it could
  16. be written to run more quickly.
  17.  
  18. #include <stdio.h>
  19. main()
  20. {
  21.    long double pi = 0;
  22.    long int = count;
  23.    for (count = 1; count <= 300000; count += 4) {
  24.       pi += 4.0 / count;            pi -= 4.0 / (count + 2);
  25.    }
  26.    printf("Value of pi is approx %.19Lf)", pi);
  27.    return 0;
  28. }
  29.  
  30. Any comments please???
  31.  
  32. Also, are there any 'standard' algorithm books which would demonstrate this
  33. sort of programming technique?
  34.  
  35. Thanks very much,
  36. Andrew Nesbit
  37.  
  38. --
  39. Andrew.Nesbit@f396.n634.z3.fidonet.org, Andrew Nesbit 3:634/396 (FidoNet)
  40.  
  41.